﻿/**
//  CapureImageEntity.cs
//  Marquee Moment
//  Copyright 2011 Systematix Technocrates. All rights reserved.
**/

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using NLog;

namespace MarqueeMoment.Entities
{
   
    public class CapureImageEntity
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        #region Fields

        private Int32 captureId;
        private byte[] captureImage;


        private List<CapureImageEntity> captureList;

        #endregion Fields

        #region Constructors

        public CapureImageEntity()
            : base()
        {
            captureId = 0;
            captureImage = new byte[0];
            captureList = new List<CapureImageEntity>();
        }


        #endregion Constructors

        #region Properties

        public Int32 ImageId
        {
            get { return captureId; }
            set { captureId = value; }
        }

        public byte[] CaptureImage
        {
            get { return captureImage; }
            set { captureImage = value; }
        }



        #endregion Properties

        #region Methods

        #region Public

        #endregion Public

        #region Private

        #endregion Private

        #endregion Methods

        #region Static methods

        #region Public

        /// <summary>
        /// To insert the records in tblImageCapture
        /// </summary>
        /// <param name="picparameter"> picparameter consists of the bit image to store in db</param>
        public static void Insert(SqlParameter picparameter)
        {
            #region Initialization
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = Connection.GetConnection();
            if (cmd.Connection == null)
                return;           
            
            cmd.CommandText = "[spInsertCaptureimage]";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(picparameter);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet dataSet = new DataSet();
            #endregion Initialization

            try
            {
                adapter.Fill(dataSet);

            }
            catch (Exception exc)
            {

                Dialogs.Error("Error at Insert Capture Image");
                logger.Error(exc.StackTrace);
            }
            finally
            {
                if (dataSet != null)
                    dataSet.Dispose();

                Connection.CloseConnection(cmd.Connection); 
                cmd.Dispose();
            }
        }
        /// <summary>
        /// To select Capture Image from the DB
        /// </summary>
        /// <returns></returns>
        public static DataTable SelectCaptureImage()
        {
            #region Initialization
            DataTable dt;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = Connection.GetConnection();
            if (cmd.Connection == null)
                return null;

            cmd.CommandText = "[spSelectCaptureImage]";
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet dataSet = new DataSet();
            #endregion Initialization

            try
            {
                adapter.Fill(dataSet);
                if (dataSet.Tables.Count > 0)
                {
                    dt = dataSet.Tables[0];
                    return dt;
                }
            }
            catch (Exception exc)
            {
                Dialogs.Error("Error at Select Capture Image");
                logger.Error(exc.StackTrace);
            }
            finally
            {
                if (dataSet != null)
                    dataSet.Dispose();

                Connection.CloseConnection(cmd.Connection);
                cmd.Dispose();
            }
            return null;
        }

        #endregion Public

        #endregion Static methods
    }
}
